package com.qf.main.pharmacy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.common.db.utils.CommonBeanutils;
import com.qf.main.pharmacy.common.vo.AddressVo;
import com.qf.main.pharmacy.entity.Address;
import com.qf.main.pharmacy.mapper.AddressMapper;
import com.qf.main.pharmacy.service.AddressService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author chengqiang
 * @Create 2024-02-18-9:26
 * @Description:
 */
@Service
public class AddressServiceImpl implements AddressService {

    @Resource
    private AddressMapper addressMapper;

    public Integer saveAddress(Address address) {

        return addressMapper.insert(address);
    }

    @Override
    public Integer removeAddress(int id) {

        return addressMapper.deleteById(id);
    }

    @Override
    public Integer modifyAddress(Address address) {
        return addressMapper.updateById(address);
    }

    @Override
    public Page<Address> getAddressListById(int addressUserId,int pageNum,int pageSize) {
        Page<Address> rowPage = new Page<>(pageNum, pageSize);
        QueryWrapper<Address> qw = new QueryWrapper<>();
        qw.eq(Address.COL_ADDRESS_USER_ID,addressUserId);

        return addressMapper.selectPage(rowPage,qw);
    }

    @Override
    public AddressVo getAddressById(int id) {
        QueryWrapper<Address> qw = new QueryWrapper<>();
        qw.eq(Address.COL_ADDRESS_ID,id);
        return CommonBeanutils.convertTo(addressMapper.selectOne(qw),AddressVo::new);
    }

}
